/**
 * create by young (young2f@outlook.com) on 2020/9/16
 * 选择辅料
 */


'use strict';
import React from 'react';
import {Badge, Button, Card, Form, Icon, Tag} from 'antd';

import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';
import DescriptionGroup from "../../../components/DescriptionGroup";
import ViewTitle from "../../../components/ViewTitle";

const {Meta} = Card;

moment.locale('zh-cn');

@Form.create()
@connect(({
            user,
            global,
            dynamicLabel,
            material,
            store
          }) => ({...user, ...material, ...dynamicLabel, ...global, ...store}))
export default class ModalDiscardDetail extends FormBase {
  constructor(props) {
    super(props);
    const {record = {}} = this.props;
    this.state = {...record};

  }

  componentDidMount() {
    const {record = {}} = this.props;
    const {recordId} = record;
    this.props.dispatch({
      type: 'store/findDiscardRecord',
      payload: {recordId}
    });
  }

  render() {
    const {style, discardRecord = {}, isReview = false, callback} = this.props;
    const {recordId, reviewStatus} = discardRecord;
    const labels = [
      {key: 'name', label: '物料名称'},
      {key: 'code', label: '物料编码'},
      {key: 'subcategory', label: '物料形态'},
      {key: 'number', label: '物料编号'},
      {key: 'type', label: '物料类型'},
      {key: 'count', label: '采购数量'},
      {key: 'vendor', label: '供应商'},
      {key: 'discardCount', label: '报废数量'},
      {key: 'discardReason', label: '报废原因'},
      {key: '_status', label: '审核状态'}
    ];
    let _status = <Tag color={"#33d"}>{"待审核"}</Tag>;
    _status = reviewStatus === "同意" ? <Tag color={"#3d3"}>{"同意"}</Tag> : _status;
    _status = reviewStatus === "驳回" ? <Tag color={"#d33"}>{"驳回"}</Tag> : _status;
    discardRecord._status = _status;
    const payload = {recordId, reviewStatus: "同意"};
    return (
      <div style={{...style}}>
        <ViewTitle
          title={'报废详情'}
          actions={[
            isReview && <Badge count={0} dot>
              <Icon style={{marginRight: '6px'}} type="notification" theme="twoTone" twoToneColor="#eb2f96"/>
            </Badge>,
            isReview && <Badge count={0} dot>
              <div style={{marginRight: '12px'}}>{'点击同意后，系统将扣除原料【入库批次】的可用数量'}</div>
            </Badge>,
            isReview && <Button type={'primary'} onClick={() => {
              this.props.dispatch({
                type: 'store/reviewDiscardRecord',
                payload
              }).then(res => {
                this.requestReturn(res);
                this.componentDidMount();
                callback();
              });
            }}>同意</Button>,
            isReview && <Button type={'dashed'} onClick={() => {
              payload.reviewStatus = '驳回';
              this.props.dispatch({
                type: 'store/reviewDiscardRecord',
                payload
              }).then(res => {
                this.requestReturn(res);
                this.componentDidMount();
                callback();
              });
            }}>驳回</Button>
          ]}></ViewTitle>
        {<DescriptionGroup
          labels={labels}
          values={discardRecord}
        ></DescriptionGroup>}

      </div>

    );
  }
}

